package com.yuque.service;

import com.yuque.dao.ArticleDao;
import com.yuque.pojo.article;
import com.yuque.util.fenye;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class ArticleServiceImpl implements ArticleService{
     @Autowired
     private ArticleDao articleDao;
    @Override
    public fenye fenyecha(Map mm) {
        fenye ff=new fenye();
        int pageno=Integer.parseInt(mm.get("pageNo").toString());
        int pageSize=Integer.parseInt(mm.get("pageSize").toString());
        int yema=(pageno-1)*pageSize;
        mm.put("pageNo",yema);
        System.out.println(pageno);
        List<Map> chaxun = articleDao.chaxun(mm);
        int totle = articleDao.cha(mm);
       ff.setMapList(chaxun);
        ff.setTotle(totle);
        return ff;
    }

    @Override
    public int insert(article article) {
        int i=0;
        if(article.getId()==null){
         i = articleDao.insert(article);
        }else {
            i=articleDao.updateById(article);
        }

        return i;
    }

    @Override
    public Map cha(Integer id) {
        Map chaid = articleDao.chaid(id);
        return chaid;
    }

    @Override
    public int deleteByid(Integer id) {
        int i = articleDao.deleteById(id);
        return i;
    }

}
